from mini_courtana import Track
from mini_courtana import Event


def read(filename):
    """
    | T | Total # of events in this track |     |     | Color | Label |
    | P | Lock status | Begin frame | End frame | Comment | Color |   |
    """
    id_ = -1
    tracks = []
    with open(filename) as f:
        for line in f:
            line = line.strip()
            elements = line.split(',')
            if len(elements) == 3:
                id_ += 1
                _, name, color = elements
                tracks.append(Track(id_, name, color))
            elif len(elements) == 7:
                _, _, ti, tf, comment, _, _ = elements
                ti = int(ti)
                tf = int(tf)
                event = Event(ti, tf-ti, comment)
                tracks[id_].add_event(event)
            else:
                continue
    return tracks


if __name__ == '__main__':
    annotations = read('video_2017-01-02T10_30_06.csv')
    print(annotations)
